package com.lanqiao.companymanage.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lanqiao.companymanage.entity.AssetClass;
import com.lanqiao.companymanage.mapper.AssetClassMapper;
import com.lanqiao.companymanage.service.AssetClassService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 何小棍
 * 资产类别管理与添加
 */
@Service
public class AssetClassServiceImpl extends ServiceImpl<AssetClassMapper, AssetClass> implements AssetClassService {
    /**
     * 分页查询
     */
    @Override
    public Page<AssetClass> listPage(Page<AssetClass> assetClassPage) {
        return baseMapper.selectPage(assetClassPage,null);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public AssetClass selectById(Integer id) {
        return baseMapper.selectById(id);
    }

    /**
     * 资产类别添加
     * @param assetClass
     * @return
     */
    @Override
    public int addAssetClass(AssetClass assetClass) {
        return baseMapper.insert(assetClass);
    }

    /**
     * 根据id删除
     */
    @Override
    @Transactional
    public int deleteById(Integer id) {
        // 删除类别表
        int deleteById = baseMapper.deleteById(id);
        // 删除关联表数据
        baseMapper.deleteAssetTea(id);
        return deleteById;
    }

    /**
     * 根据id修改
     */
    @Override
    public int updateAssetClass(AssetClass assetClass) {
        return baseMapper.updateById(assetClass);
    }

    /**
     * 查询全部类别
     */
    @Override
    public List<AssetClass> selectAll() {
        return baseMapper.selectList(null);
    }
}
